<template>
  <el-dialog
    :title="title"
    :visible.sync="innerVisible"
    width="600px"
    @close="handleCancel"
  >
    <el-form
      :model="form"
      :rules="rules"
      ref="formRef"
      label-width="180px"
    >
      <el-form-item label="所属园区" prop="parkId">
        <el-select
          placeholder="所属园区"
          v-model="form.parkId"
          clearable
          :disabled="isDetail"
        >
          <el-option
            v-for="item in parkOptions"
            :key="item.pkid"
            :label="item.name"
            :value="item.pkid"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="户型" prop="type">
        <el-input
          v-model="form.type"
          placeholder="请输入"
          :disabled="isDetail"
        />
      </el-form-item>

      <el-form-item label="户型面积(平方米)" prop="area">
        <el-input
          v-model="form.area"
          type="number"
          placeholder="请输入"
          :disabled="isDetail"
        />
      </el-form-item>

      <el-form-item label="户型套数">
        <el-input
          v-model="form.number"
          type="number"
          placeholder="请输入"
          :disabled="isDetail"
        />
      </el-form-item>
    </el-form>

    <div
      slot="footer"
      class="dialog-footer"
      v-if="!isDetail"
    >
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" @click="handleConfirm"
        >确定</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
import {
  parkOptions,
  assetsOptions,
  responseOptions
} from '@/utils/project/data'
import { queryParkInfo } from '@/api/dataManagement'

export default {
  name: 'ProgressDialog',
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    title: {
      type: String,
      default: '填写信息'
    },
    isDetail: {
      type: Boolean
    },
    currentData: {
      type: Object
    }
  },
  data() {
    return {
      form: {
        parkId: '',
        pkid: '',
        name: '',
        remark: '商业载体',
        unit: '',
        checkFlag: '是',
        type: ''
      },
      rules: {
        parkId: [
          {
            required: true,
            message: '请选择园区',
            trigger: 'blur'
          }
        ],
        area: [
          {
            required: true,
            message: '请输入户型面积',
            trigger: 'blur'
          }
        ]
      },
      innerVisible: false,
      parkOptions: []
    }
  },
  computed: {
    // parkOptions() {
    //   return parkOptions
    // },
    assetsOptions() {
      return assetsOptions
    },
    responseOptions() {
      return responseOptions
    }
  },
  mounted() {
    this.getList()
  },
  watch: {
    visible(val) {
      this.innerVisible = val
    },
    innerVisible(val) {
      this.$emit('update:visible', val)
    },
    currentData(val) {
      this.form = val
    }
  },
  methods: {
    getList() {
      const params = {
        pageIndex: 1,
        pageSize: 999
      }
      queryParkInfo(params).then((res) => {
        if (res.success) {
          this.parkOptions = res.data.list
        }
      })
    },
    handleCancel() {
      this.$emit('update:visible', false) // 父组件控制 visible
    },
    handleConfirm() {
      this.$refs.formRef.validate((valid) => {
        if (valid) {
          this.$emit('confirm', { ...this.form })
          this.handleCancel()
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~@/assets/css/dialog.scss';
::v-deep .el-input__inner {
  width: 320px !important;
}
</style>
